package com.fit.carservice.services;

import java.io.IOException;

import org.apache.tapestry5.*;
import org.apache.tapestry5.hibernate.HibernateSymbols;
import org.apache.tapestry5.hibernate.HibernateTransactionDecorator;
import org.apache.tapestry5.ioc.Configuration;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.OrderedConfiguration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.Local;
import org.apache.tapestry5.ioc.annotations.Match;
import org.apache.tapestry5.services.Request;
import org.apache.tapestry5.services.RequestFilter;
import org.apache.tapestry5.services.RequestHandler;
import org.apache.tapestry5.services.Response;
import org.slf4j.Logger;

import com.fit.hibernate.CItyServiceHibernate;
import com.fit.hibernate.CarsServiceHibernate;
import com.fit.hibernate.ClientAddressServiceHibernate;
import com.fit.hibernate.ClientsServiceHibernate;
import com.fit.hibernate.UsersServiceHibernate;
import com.fit.service.CarsI;
import com.fit.service.CitiesI;
import com.fit.service.ClientsAddressIservice;
import com.fit.service.ClientsI;
import com.fit.service.UsersI;

/**
 * This module is automatically included as part of the Tapestry IoC Registry, it's a good place to
 * configure and extend Tapestry, or to place your own service definitions.
 */
public class AppModule
{
    public static void bind(ServiceBinder binder)
    {
        // binder.bind(MyServiceInterface.class, MyServiceImpl.class);

        // Make bind() calls on the binder object to define most IoC services.
        // Use service builder methods (example below) when the implementation
        // is provided inline, or requires more initialization than simply
        // invoking the constructor.
    	binder.bind(CarsI.class, CarsServiceHibernate.class);
    	binder.bind(CitiesI.class,CItyServiceHibernate.class);
    	binder.bind(ClientsAddressIservice.class , ClientAddressServiceHibernate.class);
    	binder.bind(ClientsI.class, ClientsServiceHibernate.class);
    	binder.bind(UsersI.class, UsersServiceHibernate.class);
    }

    public static void contributeFactoryDefaults(
            MappedConfiguration<String, Object> configuration)
    {
        // The application version number is incorprated into URLs for some
        // assets. Web browsers will cache assets because of the far future expires
        // header. If existing assets are changed, the version number should also
        // change, to force the browser to download new versions. This overrides Tapesty's default
        // (a random hexadecimal number), but may be further overriden by DevelopmentModule or
        // QaModule.
        configuration.override(SymbolConstants.APPLICATION_VERSION, "1.0-SNAPSHOT");
    }

    public static void contributeApplicationDefaults(
            MappedConfiguration<String, Object> configuration)
    {
        configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
        configuration.add(HibernateSymbols.EARLY_START_UP, "true");
    }
    public static void contributeHibernateEntityPackageManager(
            Configuration<String> configuration) {
    configuration.add("com.fit.beans");
    }

@Match("*CarsI")
public static <T> T decorateTransactionallyCars(
            HibernateTransactionDecorator decorator, Class<T> serviceInterface,
            T delegate, String serviceId) {
    return decorator.build(serviceInterface, delegate, serviceId);
}
@Match("*CitiesI")
public static <T> T decorateTransactionallyCities(
            HibernateTransactionDecorator decorator, Class<T> serviceInterface,
            T delegate, String serviceId) {
    return decorator.build(serviceInterface, delegate, serviceId);
}
@Match("*ClientsAddressIservice")
public static <T> T decorateTransactionallyClientsAddress(
            HibernateTransactionDecorator decorator, Class<T> serviceInterface,
            T delegate, String serviceId) {
    return decorator.build(serviceInterface, delegate, serviceId);
}
@Match("*ClientsI")
public static <T> T decorateTransactionallyClients(
            HibernateTransactionDecorator decorator, Class<T> serviceInterface,
            T delegate, String serviceId) {
    return decorator.build(serviceInterface, delegate, serviceId);
}
@Match("*UsersI")
public static <T> T decorateTransactionallyUsers(
            HibernateTransactionDecorator decorator, Class<T> serviceInterface,
            T delegate, String serviceId) {
    return decorator.build(serviceInterface, delegate, serviceId);
}
  
}
